package com.qfedu.labsystem.controller;

import com.qfedu.labsystem.entity.bo.LabBO;
import com.qfedu.labsystem.entity.vo.ResultOBJ;
import com.qfedu.labsystem.service.LabService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName LabController
 * @Author ykx
 * @Date 2024/4/6 20:24
 * @Version 1.0
 */
@RestController
@RequestMapping("/adminapi/lab")
public class LabController {

    @Autowired
    private LabService labService;

    @GetMapping
    public List<LabBO> getLabList(LabBO lab) {
        return labService.getLabList(lab);
    }

    @PostMapping
    public ResultOBJ addLabList(@RequestBody LabBO lab) {
        try {
            labService.addLab(lab);
            return ResultOBJ.ADD_SUCCESS;
        } catch (Exception e) {
            return ResultOBJ.ADD_ERROR;
        }
    }

    @PutMapping("/{id}")
    public ResultOBJ updateLabList(@PathVariable Integer id, @RequestBody LabBO lab) {
        lab.setId(id);
        return ResultOBJ.success(labService.updateLab(lab));
    }

    @DeleteMapping("/{id}")
    public ResultOBJ deleteLabList(@PathVariable Integer id) {
        return ResultOBJ.success(labService.deleteLab(id));
    }

}
